$OutputEncoding = [System.Text.Encoding]::UTF8
Write-Host "========== 明日方舟自动化脚本 ==========" -ForegroundColor Green
“ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
fffffffffffffffffffffffffffWffffffffffffffffffffffffffffffffffffffffff
fffffffffffffffffffffffffff#ffffffffffffffffffffffffffffffffffffffffff
fffffffffffffffffffffffffff#Wfffffffffffffffffffffffffffffffffffffffff
fffffffffffffffffffffffffff##Efffffffffffffffffff#ffffffffffffffffffff
fffffffffffffffffffffffffffGj,fffffffffffffffffW#fffffffffffffffffffff
fffffffffffffffffffffffffffj:,:ffffffffffffffW;#Kfffffffffffffffffffff
ffffffffffffffffffffffffffW;#:i.ff##fffffffW..:tLfffffffffffffffffffff
ffffffffffffffffffffffffff;G#jiGW.W.;j..i#...f:ttfffffffffffffffffffff
ffffffffffffffffffffffffff;j...ji...,:......K#::Dfffffffffffffffffffff
ffffffffffffffffffffffffff;L..f...,tfGjtG..W.L#;ffffffffffffffffffffff
ffffffffffffffffffffffffff;#t.....###KGD#W..i.iL#fffffffffffffffffffff
fffffffffffffffffffffffff#;#L#...##W####W##..tLGffffffffffffffffffffff
fffffffffffffffffffffffff;##j...#...j..:.K#W..fL#fffffffffffffffffffff
ffffffffffffffffffffffffK;##j..,;j......,..i..##ffffffffffffffffffffff
ffffffffffffffffffffffff;;j#.. ;...........;K..fffffffffffffffffffffff
fffffffffffffffffffffffGD###..W,...... .. .., .fLfffffffffffffffffffff
fffffffffffffffffffffff;#f#........... ... .....ffffffffffffffffffffff
fffffffffffffffffffffff;;#G..W.....D........::..#fffff f fffffffffffff
ffffffffffffffffffffffiftj,..;.:..:.;..........:K#ffffffffffffffffffff
fffffffffffffffffffffj;;;;..W.j.t.......iK.......ffffffiffffffffffffff
fffffffffffffffffffffW;;tj..;.LK.LW......t.......fff fffffffffffffffff
fffffffffffffffffffff;Gf;j.G;..ifDf,..jD.D.f.:...#ffffffffffffffffffff
fffffffffffffffffffft;;;;E.;..:::W#......#:GK...Efffffffffffffffffffff
ffffffffffffffffffffW;;;;..;...  ,i....::EK#t...ff#fffffffffffffffffff
ffffffffffffffffffff;;;;G.K,...........  ;..Lj.Dffffffffffffffffffffff
fffffffffffffffffffji;;Lj.j...E............DjiK.ffffffffffffffffffffff
ffffffffffffffffffffj;;jj.j...:...........fLj,.:ffffffffffffffffffffff
fffffffffffffffffffED;;jj,j...:i..........jjt..jKfffffffffffffffffffff
fffffffffffffffffffWWi;jj#j:.:j...........jjj;E;#fffffffffffffffffffff
fffffffffffffffffffWLj;WjGj#;;jW.........jjj.,#;#Kffffffffffffffffffff
fffffffffffffffffffjff;fjLjj;.jGi#.....LjjfG.#f;#fffffffffffffffffffff
fffffffffffffffffffffj;fj#jj..jDiiDD.KjjjjjK.jf;Df#fffffffffffffffffff
fffffffffffffffffffiEf;fLfjE:.j;,iiKKtLjjfGDijf#Kfffffffffffffffffffff
ffffffffffffffffffE#..#;EfffW.f;;;;,t;;fEff,f;;#...fffffffffffffffffff
ffffffffffffffffffi#....;;fG#.;;;;i;i#iiEWf.;;.....fffffffffffffffffff
ffffffffffffffffffLf..;..;;;#E#i;;;##L#t##j;Lt.....fffffffffffffffffff
fffffffffffffffffftjEGt.,.;;#j##;;##WED#.##;;......fffffffffffffffffff
fffffffffffffffffftt#jt...;;#E##,.G#jjjGGGD#.......fffffffffffffffffff
fffffffffffffffff#tE###....;#E:GGGLLEGDjDDGD..i;jjDLffffffffffffffffff
fffffffffffffffffttD###.,:..EK:DG#KEEDKDDGGG#.......ffffffffffffffffff
ffffffffffffffffftt###.;;.;.W;GGGGGGGGGGGDGDD.:;i...ffffffffffffffffff
fffffffffffffffff#tf##,.....E;fDjG#.EKG#W.#.D..j:...ffffffffffffffffff
fffffffffffffffffftj##......K;t...,:......;.:..:;;.Kffffffffffffffffff
ffffffffffffffffffLtW##...f.,;fi:...Lj:.t,i..:.#.;WGffffffffffffffffff
ffffffffffffffffff#W####.;t;Ef..;.....ti.......i,..##fffffffffffffffff
ffffffffffffffffffEGEW##;..f;D.........;...........DGfffffffffffffffff
fffffffffffffffff#GDDG#f.;;;..t..................D:GKfffffffffffffffff
fffffffffffffffffDGGGG#...:;:....................f###fffffffffffffffff
fffffffffffffffffG##D###.t;;...,;;,:........:;;;;D##ffffffffffffffffff
fffffffffffffffff#######ftE;:;;;;;;;;;,:.,.,;;;;;G.fffffffffffffffffff
ffffffffffffffffff##E####;i;L;;.;;;;;;;;.,;;;;;;;;ffffffffffffffffffff
ffffffffffffffffffff##E##L;;i;;;;;;;;;;;:;;;;;;:L#ffffffffffffffffffff
fffffffffffffffffffffEWKW;;;;D;;;;;;;;;;;;;;;;;;t#ffffffffffffffffffff
fffffffffffffffffffffE#####t;;i;j;;;;;;i;;;;;;jj#Dffffffffffffffffffff
fffffffffffffffffffffKE#####;;t;t;;;;t;;;;;;;;;j#Gffffffffffffffffffff
fffffffffffffffffffff#######G;;t;;;;;;K;;;G;tDt;#Dffffffffffffffffffff
ffffffffffffffffffffff#######;;tDj;E#WGGGGGG#jtK##ffffffffffffffffffff
ffffffffffffffffffffffE######Wt##K#EKEGGGGGG#ttG#Gffffffffffffffffffff
ffffffffffffffffffffffEE####tK###D#EKW##KLti#tWK#Dffffffffffffffffffff
fffffffffffffffffffGG;EE###Et###D##D#K;i.......;#Dffffffffffffffffffff
fffffffffffffffff;;;;;K##W#EjE###j;L........;i.;##ffffffffffffffffffff
ffffffffffffffffE;;;;EW#EEW#E#;W#i.........;LLLjL#ffffffffffffffffffff
ffffffffffffffffG;;;;iEE####j;;DLj;i;..:f;j.t...t.#fffffffffffffffffff
ffffffffffffffffft;;;KE#W#W;;;t#G;j.;..;....j..;.i.tffffffffffffffffff
fffffffffffffffffEtG;EK#W##;;;K##;..;..t;...;.t....,ffffffffffffffffff
ffffffffffffffffffE;#E####;G;WKG;;.....,:...;..;....tfffffffffffffffff
ffffffffffffffffffG;E#####;,;;##;,,.....;...;..;....iGffffffffffffffff
fffffffffffffffffffK####G;;;;##t;.......;;..;..:;...j..Effffffffffffff
ffffffffffffffffffft####;;i;;#E;;.......i;;:;...;.....,.ffffffffffffff
fffffffffffffffffffD####;tt;;#E;.........;;;;...;;;...;;ffffffffffffff
fffffffffffffffffft#####;;j;;#;;.;:......;;;;...;;..i..;ffffffffffffff
fffffffffffffffffG;#####f;j;K#t;.;.......t;;;....;;,...;Wfffffffffffff
fffffffffffffffffL;;###t;;;;#W;..;........;;;....;.........fffffffffff
fffffffffffffffff;;###;;;;;;#E;..;........;;.....;....;....fffffffffff
fffffffffffffffff;L###;;tj;;#j;.;;........;;.....;.....;.t.Lffffffffff
WWKDLfffffffffffD;####;;L;j##;;.;;.....................ii.;Wffffffffff
DDDDDDDDDDDDDDD#i#####G;tL;##;;.;;................;.....;....:ffffffff
DDDDDDDDDDDDDDDG#######;;jG;#;;.;i.....,..........,,....L;....ffffffff
DDDDDDDDDDE;iii;#####;;;;,E##;;.;......;;.........;;.....;;...ffffffff
LLLDDDDDDti#;ji####W#;;;LKW;#;;.;......;;;.i.......;;....j;,.;ffffffff
LLLLLLLDGDD#ii#####W#;;Gt;i#;;;.;......;;;::.......;;i..;.,;.Effffffff
LLLLLLLLLLGEDD####K###;;;;t;;;;;;......;;;;........L;;..;.:.tfffffffff
LLLLLLLLLLE#K#########;;;t;;tit;;;;:...;;;;......;..;;;.;.....ffffffff
DDDDDDDDDDDD#####W###i;;.t..;ft;;;;;i..;;.;:....,;;.;;;.;L....ffffffff
DDDDDDDDDDDK#####K####;f....;tG;t;;;;i.;;.;,....;;;L;;;;;;...,ffffffff
###WKGfffff############t...iG:jf;;;;;;i;..;;.j;.;;;;,i..;;f..#ffffffff
##Lfffffff##########WE###..t.;;fi;.;;;;;t.;;;;;f;;;.t,:..f;.#KGfffffff
##ffffffff#####W###DW####....;..;D.;.t;;;:.;G;;;;.L.:;....t;#KGfffffff
##fffffff#####K##EDD###E##...E..;.,t.:;,t.,L;;..;..;.t...t;#E#DDffffff
##fffffff#####EWDDDG##DG##i.i..;.......t....;;........:.####D##D#fffff
##Lfffff#####EEGDGGG##WD#####..;.......;....;;...j...E;####DDG#KDfffff
##GGGffD#####EDGGDDD##GD######j;t...........G;...f..#j##DGGDDDD#D#ffff
##GGGGG#####EDGDDGGG#EDD#W#E####E####G.......;.#t.j####DDDGDGDD##Gffff
##GGGG######EDDGGGGD#DGDDDGDGGE##E###...D##tW;W####WGDDDGGDGGDDD#DKfff
##GGGGG####WDGDGDGGWEGGGGDGGGGGE#WE#E########KE##WDGDGGGGGDDDDGD##jfff
##GGGGGf###EDGGGGGG#DGGGDGDGGGGDGGDGGGE#WWGD#GGDDGGGGGGDGDGDGDDDD#j#ff
##GGGGLi;##EGGGGGGD#DDGGDDDGDGDGGGGGDGGDDDGG#DDGGGGGDDDGGGGGGGGGD..;ff
##GGGG;i;LWi#GGGGG#EGGGGGGGGGGGDGDDGDGGGDDGGKDDGGDGGGGDGDGGDGGDG#..Lff
##GGGG;Gtjj;;;DGDD#DGGGGDGGGGGGGDGDDGGGGGGGDEDGGGDGGGDGGGGGGDGG#..:fff
##GGGGGGjWttL;;#D##fttKGDDGDGGDDGDGDDDGDGGGGEDGGDDDGGDGDGGGGDG;.,jKfff
##GGGGGGG;i;;;;;;###LtL;#GGGDDDDDDGDDGGGGGDDGGDGGGDGDGGGGDGG#i..iDffff
##GGGGGGGGtG;;;;LjK##Wf;;;tDDDGGGGGGDGGGGGGGGDDGGGGGGGDGDGG;.i.jLEffff
##GGGGGGGGfjG;L;;;f;;#j.L.;;;#DGGGGGGGDGDGGDGKDGDGDDDGGDG#;...#.ffffff
##GGGGGGGGGGG;KG;;G;;..;.;jt;;;;GEGGDDDGGGEKWKGGGGGK#Kij:..t..;fffffff
##GGGGGGGGGGGGGGDj;;Ljt.i.::t;L;..jjj;;;;;.:;L...;jj...;....ffffffffff
##GGGGGGGGGGGGGGGGGG;G.EG.:t;...t.t;...t;...jGi.i...i.f.LWfWffffffffff
##GGGGGGGGGGGGGGGGGGGGGGGGji.ii.ii...t.it.Et,jE.E.K.Gfffffffffffffffff
##GGGGGGGGGGGGGGGGGGGGGGGGD;KiiiiiEjiL;WiiiiG,iiiiLLffffffffffffffffff
##GGGGGGGGGGGGGGGGGGGGGGGGG;i;;i;;E;;i;D;;;itEjti;GGLfffffffffffffffff
##GGGGGGGGGGGGGGGGGGGGGGGGGii;;;;;;i;i;Gi,;;i;;,;iGGGGLfffffffffffffff
##GGGGGGGGGGGGGGGGGGGGGGGGGWii.t..,;;;fti,,i;i;i;WGGGGGGLfffffffffffff
##GGGGGGGGGGGGGGGGGGGGGGGGGG;  .::  .,#;;,;ii;,;;GGGGGGGGGLfffffffffff
##GGGGGGGGGGGGGGGGGGGGGGGGGGi:  .  .::#ii;;,i,,;iGGGGGGGGGGGLfffffffff
##GGGGGGGGGGGGGGGGGGGGGGGGGGW;::::::::Kiiiiiiiii#GGGGGGGGGGGGGLfffffff
##GGGGGGGGGGGGGGGGGGGGGGGGGGGi::::::::DiiiiiiiiiGGGGGGGGGGGGGGGGLfffff”
Write-Host "========== 1.开始检查脚本环境 =========" -ForegroundColor Green
# 1、进入桌面
cd ~/Desktop

# 2、判断 test 文件夹是否存在，不存在就创建
if (!(Test-Path "test")) {
    # 2-1、不存在，创建一个 test 文件夹
    New-Item -Name "test" -ItemType Directory
    Write-Host "✅ test文件夹创建完成“ -ForegroundColor Green
} else {
    Write-Host "⚠ test文件夹已存在" -ForegroundColor Yellow
}

# 3、进入test文件夹，并清空里面的所有内容（用于更新操作）
cd test
<#
    # * 所有文件
    -Recurse 递归删除
    -Force 强制删除只读或隐藏文件
#>
Remove-Item * -Recurse -Force -ErrorAction SilentlyContinue

# 4、下载 游戏脚本 jar 文件
# -ErrorAction SilentlyContinue 警告报错，不输出，防止影响脚本执行
$gitExists = Get-Command git -ErrorAction SilentlyContinue
# 项目 git 链接
$activitiesUrlGit = "https://gitee.com/mabingzheng/activities-plug.git"
# 项目 git zip 链接
$activitiesUrlZip = "https://github.com/PonyMBZ/Arknights-Plug-Project/archive/master.zip"
# zip 文件名
$outputZip = "activities-plug.zip"
# 解压路径
$extractPath = "~/Desktop/test"

# 4-1、判断 用户电脑是否有git
# 检查 git 是否存在，不报错
Write-Host "1、检查 git 环境" -ForegroundColor Green
if ($gitExists) {
    # 有 git 直接 git clone 安装
    Write-Host "✅ Git 已安装，路径: $($gitExists.Source)" -ForegroundColor Green
    git clone $activitiesUrlGit
} else {
    # 没有 git 就先安装 zip 然后在解压
    Write-Host "⚠ Git 未安装" -ForegroundColor Yellow
    # 下载 ZIP 文件
    Invoke-WebRequest -Uri $activitiesUrlZip -OutFile $outputZip
    # 解压 ZIP 文件
    Expand-Archive -Path $outputZip -DestinationPath $extractPath -Force
    # 删除 ZIP 文件
    Remove-Item $outputZip -Force
}

Write-Host "✅ 脚本下载完成" -ForegroundColor Green

# 4-2、判断是否有 java 环境（JDK17）
# 1. 检查 java -version
Write-Host "2、检查 java 环境" -ForegroundColor Green
$versionOutput = java -version 2>&1
# 正则判断
if ($versionOutput -match 'version "17\.') {
    Write-Host "[√] 默认 Java 版本是 17" -ForegroundColor Green
} else {
    Write-Host "⚠ 默认 Java 版本不是 17" -ForegroundColor Yellow
}
